#pragma once
#include<iostream>
#include<cassert>
using namespace std;
class Date
{
public:
	Date(int year = 2024, int month = 1, int day = 6)
	{
		//_a = (int*)malloc(sizeof(int) * ad + 1);
		_year = year;
		//_ad = ad;
		_month = month;
		_day = day;
	}
	~Date()
	{
		_year = _month = _day = 0;
		//free(_a);
	}
	Date(const Date& d)
	{
		//_a = (int*)malloc(sizeof(int) * d._ad + 1);
		_year = d._year;
		_ad = d._ad;
		_month = d._month;
		_day = d._day;
	}
	Date GetAfterxDay(int x)
	{
		Date tmp(*this);
		tmp._day += x;
		while (tmp._day > GetMonthDay(tmp._year, tmp._month))
		{
			tmp._day -= GetMonthDay(tmp._year, tmp._month);
			tmp._month++;
			if (tmp._month > 12) {
				tmp._year++;
				tmp._month = 1;
			}
		}
		return tmp;
	}
	int GetMonthDay(int year, int month)
	{
		assert(month > 0 && month < 13);
		int monthArray[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
		if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {
			return 29;
		}
		else return monthArray[month];
	}
	Date& operator+=(int day)
	{
		_day += day;
		while (_day > GetMonthDay(_year, _month)) {
			_day -= GetMonthDay(_year, _month);
			_month++;
			if (_month == 13) {
				++_year;
				_month = 1;
			}
		}
		return *this;
	}
	Date operator+(int day)
	{
		Date tmp(*this);
		tmp += day;
		return tmp;
	}
	Date& operator++()
	{
		*this += 1;
		return *this;
	}
	Date operator++(int)
	{
		Date tmp(*this);
		*this += 1;
		return tmp;
	}
	void print()
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}
	int _ad;
	//private:
	int* _a;
	int _year;
	int _month;
	int _day;
};
